{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv\n",
    "filename = \"lena.jpg\"\n",
    "img = cv.imread(filename)\n",
    "cv.imshow(\"Hello, world!\", img)\n",
    "key = cv.waitKey()\n",
    "while (key != 32):\n",
    "    key = cv.waitKey()\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Hello, word!截图\n",
    "![hello](hello_world.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv\n",
    "import numpy as np\n",
    "\n",
    "filename = \"lena.jpg\"\n",
    "img = cv.imread(filename)\n",
    "cv.imshow(\"origin\", img)\n",
    "\n",
    "gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)\n",
    "cv.imshow(\"gray\", gray)\n",
    "\n",
    "b,g,r = cv.split(img)\n",
    "x = np.zeros(r.shape, dtype=np.uint8)\n",
    "bimg = cv.merge([b, x, x])\n",
    "gimg = cv.merge([x, g, x])\n",
    "rimg = cv.merge([x, x, r])\n",
    "cv.imshow(\"Blue\", bimg)\n",
    "cv.imshow(\"Green\", gimg)\n",
    "cv.imshow(\"Red\", rimg)\n",
    "\n",
    "hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)\n",
    "#cv.imshow(\"HSV\", hsv)\n",
    "\n",
    "h,s,v = cv.split(hsv)\n",
    "y = np.full(h.shape, 255, dtype=np.uint8)\n",
    "cv.imshow(\"Hue\", h)\n",
    "cv.imshow(\"Saturation\", s)\n",
    "cv.imshow(\"Value\", v)\n",
    "\n",
    "hhsv = cv.merge([h, y, y])\n",
    "himg = cv.cvtColor(hhsv, cv.COLOR_HSV2BGR)\n",
    "cv.imshow(\"himg\", himg)\n",
    "\n",
    "key = cv.waitKey()\n",
    "while (key != 32):\n",
    "    key = cv.waitKey()\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对比分析：\n",
    "\n",
    "    RGB分量：\n",
    "    \n",
    "   ![RGB分量图](lena_rgb.png)\n",
    "    \n",
    "    在RGB分量图中，越亮的地方说明该颜色在原图中占的比例更大一些，越暗则说明该颜色在原图中占的比例比较小\n",
    "    \n",
    "    HSV分量：\n",
    "    \n",
    "   ![HSV分量图](lena_hsv.png)\n",
    "    \n",
    "    H分量图中，越亮的地方，色调越接近紫色，越暗的地方色调越接近红色，himg是保留H分量并将S和V分量设置为最大值后转换为BGR模式的图像，可以清晰的看到各部分的颜色，其中帽子、人脸、皮肤更接近红色，在Hue分量图像中显示更暗，帽子上的毛线更接近紫色，在Hue分量图像中则更亮；\n",
    "    S分量图中，原图越鲜艳的地方越亮，原图颜色越暗淡的地方越暗，帽子上的毛线，头发，眼睛等地方更鲜明，在S分量图中更亮；\n",
    "    I分量图与原图的明暗保持一致，更接近灰度图；"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
